package edu.cmu.cs.stage3.alice.authoringtool.viewcontroller;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;

/**
 * @author Jason Pratt
 */
public class KeyCodePropertyViewController extends PropertyViewController {
	protected javax.swing.JLabel keyLabel = new javax.swing.JLabel();

	public void set( edu.cmu.cs.stage3.alice.core.Property property, boolean allowExpressions, final edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory factory ) {
		super.set( property, true, allowExpressions, false, true, factory );
		refreshGUI();
	}

	//Rem @Override
	protected java.awt.Component getNativeComponent() {
		return keyLabel;
	}

	//Rem @Override
	protected Class getNativeClass() {
		return Integer.class;
	}

	//Rem @Override
	protected void updateNativeComponent() {
		javax.swing.ImageIcon icon = AuthoringToolResources.getIconForValue( property.get() );
		if( icon != null ) {
			keyLabel.setText( null );
			keyLabel.setIcon( icon );
		} else {
			keyLabel.setText( AuthoringToolResources.getReprForValue( property.get(), property, property.getOwner().data ) );
			keyLabel.setIcon( null );
		}
	}

	//Rem @Override
	public void getHTML(StringBuffer toWriteTo){
		toWriteTo.append(AuthoringToolResources.getReprForValue( property.get(), property, property.getOwner().data ) );
	}

}
